<template>
	<router-view></router-view>
</template>

<script setup>
import { onMounted } from "vue";
import router from '@/router';
import store from '@/store';
import api from "./api";
import { ElMessage } from "element-plus";

onMounted(()=>{
	//获取token，并进行判断是否为未登录
	let token = window.localStorage.getItem("token")
	//如果未空，那么将进行页面跳转
	if(!token){
		console.log("token为空将")
		router.push("/welcome")
		return
	}
	api.get('api/user/checkToken').then((resp)=>{
		if(resp.data.code == 401){
			window.localStorage.removeItem("token");
			ElMessage.success(resp.data.msg)
			router.push("/login")
		}
		return
	})
	console.log("不为空将进行设置信息并更新")
	console.log(token)
	//不为空将进行设置信息并更新
	store.state.user.name = window.localStorage.getItem("name");
	store.state.user.role = window.localStorage.getItem("role");
	store.state.user.account = window.localStorage.getItem('account');
	store.state.user.img = window.localStorage.getItem("img");
})
	
</script>

<style>
	#app {
		font-family: Avenir, 
		Helvetica, 
		Arial, 
		sans-serif;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
		/* text-align: center; */
		color: #2c3e50;
		/* margin-top: 60px; */
	}
	
	*{
		margin: 0;
		user-select: none;
		-webkit-user-select: none;
		-moz-user-select: none;
		-ms-user-select: none;
	}
	
	body{
		min-width: 1000px;
	}
	
</style>